<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
if (!defined('__BACKEND__'))
    die("you cannot directly access this page");
function list_tag(){
    global $db,$page,$pagesize;
    if (empty($page)){
        $start=0;
    } else {
        $start=$page*$pagesize;
    }
    $sql="select a.*,b.word,c.title 
          from _post_tags a,_keywords b,_post_contents c
          where a.word_id=b.id and a.post_id=c.id
          order by b.word limit $start,$pagesize";
    $result=$db->query($sql);
    $nrow=mysql_num_rows($result);
    if ($nrow>0){
        echo "<h2>List of Tag</h2>
            <table width=\"100%\" cellspacing=0><tr><th>No</th><th>News Title</th><th>Keyword</th><th>Action</th></tr>";
        $i=0;
        while ($row=$db->fetch_array($result)){
            extract($row);
            $i++;
            echo "<tr><td align='center'>$i</td>
            <td>$title</td><td>$word</td><td align='center'>
            <a href=\"?mod=panel&file=tags&post_id=$post_id&word_id=$word_id&action=delete\">
            <img class='icon' src=\"images/delete.png\" title=\"Delete Tag\"/></a>
            </td></tr>";
        }
        echo "</table>";
    }
    
}
function delete(){
    global $db,$word_id;
    $channel_name=show_word($word_id);
    $post_title=get_post_info($post_id, 'title');
    $msg= "Word $channel_name on $post_title was deleted!";
    
    $db->query("delete from _post_tags where word_id=$word_id and post_id=$post_id");
    refresh_to("?mod=panel&file=tags", $msg, 2);
}
global $action;
switch($action){
    case 'delete':
        delete();
        break;
    default:
        list_tag();
}
?>
